package com.industrial.premu.controller;


import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.premu.domain.PreMuPioneerDeveZone;
import com.industrial.premu.domain.PremuPioneerCompany;
import com.industrial.premu.domain.vo.PreMuPioneerCountVo;
import com.industrial.premu.service.IPreMuPioneerDeveZoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/premu/kfp/xf")
public class PreMuPioneerDeveZoneController extends BaseController {

    @Autowired
    private IPreMuPioneerDeveZoneService preMuPioneerDeveZoneService;

    /**
     * 查询开发区先锋列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PreMuPioneerDeveZone preMuPioneerDeveZone)
    {
        startPage();
        List<PreMuPioneerDeveZone> list = preMuPioneerDeveZoneService.selectPreMuPioneerDeveZoneList(preMuPioneerDeveZone);
        return getDataTable(list);
    }


    /**
     * 查询开发区先锋列表排名前10
     */
    @GetMapping("/listTop15")
    public List<PreMuPioneerDeveZone> listTop10(PreMuPioneerDeveZone preMuPioneerDeveZone)
    {
        List<PreMuPioneerDeveZone> list = preMuPioneerDeveZoneService.listTop10(preMuPioneerDeveZone);
        return list;
    }


    /**
     * 导出开发区先锋列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, PreMuPioneerDeveZone preMuPioneerDeveZone)
    {
        List<PreMuPioneerDeveZone> list = preMuPioneerDeveZoneService.selectPreMuPioneerDeveZoneList(preMuPioneerDeveZone);
        ExcelUtil<PreMuPioneerDeveZone> util = new ExcelUtil<PreMuPioneerDeveZone>(PreMuPioneerDeveZone.class);
        util.exportExcel(response, list, "开发区先锋数据");
    }

    /**
     * 获取开发区先锋详细信息
     */
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(preMuPioneerDeveZoneService.selectPreMuPioneerDeveZoneByBaseId(baseId));
    }

    /**
     * 新增开发区先锋
     */
    @PostMapping
    public AjaxResult add(@RequestBody PreMuPioneerDeveZone preMuPioneerDeveZone)
    {
        return toAjax(preMuPioneerDeveZoneService.insertPreMuPioneerDeveZone(preMuPioneerDeveZone));
    }

    /**
     * 修改开发区先锋
     */
    @PutMapping
    public AjaxResult edit(@RequestBody PreMuPioneerDeveZone preMuPioneerDeveZone)
    {
        return toAjax(preMuPioneerDeveZoneService.updatePreMuPioneerDeveZone(preMuPioneerDeveZone));
    }

    /**
     * 删除开发区先锋
     */
    @DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(preMuPioneerDeveZoneService.deletePreMuPioneerDeveZoneByBaseIds(baseIds));
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<PreMuPioneerDeveZone> util = new ExcelUtil<PreMuPioneerDeveZone>(PreMuPioneerDeveZone.class);
        util.importTemplateExcel(response, "亩产先锋开发区","亩产先锋开发区");
    }

    @PostMapping("/importPioneerDeveZoneData")
    public AjaxResult importPioneerDeveZoneData(@RequestPart("file")MultipartFile file,String years){
        return preMuPioneerDeveZoneService.importPioneerDeveZoneData(file,years);
    }



    // 统计接口

    /**
     * 查询统计数量
     * @param years
     * @return
     */
    @GetMapping("/queryTjCount")
    public AjaxResult queryTjCount(@RequestParam("years") String years){
        PreMuPioneerCountVo result = preMuPioneerDeveZoneService.queryTjCount(years);
        return AjaxResult.success(result);
    }

    /**
     * 先锋企业排名
     * @param years
     * @return
     */
    @GetMapping("/queryTjCompanyOrderEcharts")
    public AjaxResult queryTjCompanyOrderEcharts(@RequestParam("years") String years,@RequestParam("industry") String industry){
        Map<String, List<String>> result = preMuPioneerDeveZoneService.queryTjCompanyOrderEcharts(years,industry);
        return AjaxResult.success(result);
    }


    /**
     * 先锋区县排名
     * @param years
     * @return
     */
    @GetMapping("/queryTjCountyOrderEcharts")
    public AjaxResult queryTjCountyOrderEcharts(@RequestParam("years") String years){
        Map<String,List<String>> result = preMuPioneerDeveZoneService.queryTjCountyOrderEcharts(years);
        return AjaxResult.success(result);
    }

    /**
     * 先锋开发区排名
     * @param years
     * @return
     */
    @GetMapping("/queryTjKfqOrderEcharts")
    public AjaxResult queryTjKfqOrderEcharts(@RequestParam("years") String years,
            @RequestParam("groupName") String groupName){
        Map<String,List<String>> result = preMuPioneerDeveZoneService.queryTjKfqOrderEcharts(years,groupName);
        return AjaxResult.success(result);
    }
}
